package com.spzx.product.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.mapper.ProductSpecMapper;
import com.spzx.product.service.ICategoryService;
import com.spzx.product.service.IProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper,ProductSpec> implements IProductSpecService {
    @Autowired
    ICategoryService categoryService;
    @Override
    public List<ProductSpec> selectProductSpecList(ProductSpec productSpec) {

        return baseMapper.selectProductSpecList(productSpec);
    }

    @Override
    public ProductSpec selectProductSpecById(Long id) {
        ProductSpec productSpec = baseMapper.selectById(id);
        Long categoryId = productSpec.getCategoryId();
        List<Long> parentIds = categoryService.getParentIds(categoryId);
        productSpec.setCategoryIdList(parentIds);
        return productSpec;
    }

    @Override
    public List<ProductSpec> getProductSpecById(Long categoryId) {
        return baseMapper.getProductSpecById(categoryId);
    }
}
